﻿
using System;
using System.Collections.Generic;

namespace TestProject
{
    public class Program
    {
        static void Main(string[] args)
        {
            var books = new List<Book>();
            books.Add(new Book()
            {
                 Name="水浒传",
                 Price=98f,
            });
            books.Add(new Book()
            {
                Name="三国演义",
                Price=95.5f,
            });
            books.Add(new Book()
            {
                Name="红楼梦",
                Price=97f,
            });
            books.Add(new Book()
            {
                Name="西游记",
                Price=100,
            });

            books.Sort();
            foreach (var item in books)
            {
                string writer = string.Format("书名{0}，价格{1}", item.Name,item.Price.ToString());
                Console.WriteLine(writer);
            }

            Console.ReadKey();

        }

        class Book : IComparable
        {
            public string Name { get; set; }
            public float Price { get; set; }

            public int CompareTo(object? obj)
            {
                Book b = (Book)obj;
                if (this.Price < b.Price)
                {
                    return -1;
                }
                else if (this.Price > b.Price) 
                { 
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
        }
    }

}
